package com.css.dzj.zfjg.modules.other.controller;

import com.css.aq.server.service.BaseService;
import com.css.dzj.zfjg.common.util.R;
import com.css.dzj.zfjg.modules.fb.entity.JgFbLhjgEntity;
import com.css.dzj.zfjg.modules.other.entity.JgJgxwOtherActionEntity;
import com.css.dzj.zfjg.modules.other.service.JgJgxwOtherActionService;
import com.querydsl.core.QueryResults;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 其他行为信息
 *
 * @author liyuan
 */
@RestController
@RequestMapping("jgxw/jgjgxwotheraction")
public class JgJgxwOtherActionController {
    @Autowired
    private JgJgxwOtherActionService jgJgxwOtherActionService;

    @Autowired
    private BaseService baseService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Integer pageSize, @RequestParam Integer pageNo){
        try {
            PageRequest pageRequest = PageRequest.of(pageNo - 1, pageSize);
            QueryResults<JgJgxwOtherActionEntity> page = jgJgxwOtherActionService.queryPage(pageRequest);
            baseService.logSuccess(3, "分页查询行政其它行为成功", "2");
            return R.ok().put("page", page);
        } catch (Exception e) {
            e.printStackTrace();
            baseService.logFailed(3, "分页查询行政其它行为失败", "2");
            return R.error(e.getMessage());
        }
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
        try{
            JgJgxwOtherActionEntity jgJgxwOtherAction = jgJgxwOtherActionService.getById(id);
            baseService.logSuccess(3, "通过id获取行政其它行为信息成功", "2");
            return R.ok().put("jgJgxwOtherAction", jgJgxwOtherAction);
        } catch (Exception e) {
            e.printStackTrace();
            baseService.logFailed(3, "通过id获取行政其它行为信息失败", "2");
            return R.error(e.getMessage());
        }
    }


    /**
     * 添加其他行为
     */
    @RequestMapping("/save")
    public R addOtherAction(@RequestBody JgJgxwOtherActionEntity jgJgxwOtherActionEntity){
        try{
            jgJgxwOtherActionService.save(jgJgxwOtherActionEntity);
            baseService.logSuccess(3, "行政其它行为添加成功", "2");
            return R.ok("保存成功!");
        } catch(Exception e) {
            e.printStackTrace();
            baseService.logFailed(3, "行政其它行为添加失败", "2");
            return R.error(e.getMessage());
        }

    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody JgJgxwOtherActionEntity jgJgxwOtherAction,HttpServletRequest request){
        try{
            jgJgxwOtherActionService.updateById(jgJgxwOtherAction);
            baseService.logSuccess(3, "行政其它行为修改成功", "2");
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            baseService.logFailed(3, "行政其它行为修改失败", "2");
            return R.error(e.getMessage());
        }

    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestParam String id){
        try {
            jgJgxwOtherActionService.deleteById(id);
            baseService.logSuccess(3, "行政其它行为删除成功", "2");
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            baseService.logFailed(3, "行政其它行为删除失败", "2");
            return R.error(e.getMessage());
        }

    }


}

